#Replication File 1 for "Political Overconfidence Strengthens the Durability of Misperceptions"
#2019 MTurk Sample
#Use "Study1.csv"

dat <- read.csv("Study1.csv")

#libraries

library(ggplot2)
library(ggthemes)
library(tidyverse)
library(car)
library(sjPlot)
library(sjmisc)
library(stargazer)
theme_set(theme_sjplot())

#Table 1

mod1 <- lm(data=dat,misinfo_true~misinfo_treat)
mod2 <- lm(data=dat,misinfo_true~misinfo_treat + dunning_dif + misinfo_treat*dunning_dif)
mod3 <- lm(data=dat,misinfo_true~misinfo_treat + dunning_dif + misinfo_treat*dunning_dif + 
             know + edu + know_time_log + distract)
mod4 <- lm(data=dat,misinfo_true~misinfo_treat + dunning_dif + misinfo_treat*dunning_dif + 
             know + edu + know_time_log + distract + pidStrength + ideoStrength)

stargazer(mod1,mod2,mod3,mod4, type="html",out="mturk.html",
          star.cutoffs=c(0.05,0.01,0.001),
          covariate.labels=c(
            "T1: Consensus Cue",
            "T2: Large Majority Consensus Cue",
            "Confidence Accuracy [-1:1]",
            "Political Knowledge [0:5]",
            "Formal Education [1:6]",
            "Knowledge Battery Completion Time (log)",
            "Pre-Treatment Attention Check Success [0:4]",
            "Strength of Party ID [1:4]",
            "Ideological Strength [1:3]",
            "T1*Confidence Accuracy",
            "T2*Confidence Accuracy",
            "Constant"
          ))



#Fig. 1
#rename for easy labels
dat$Treatment <- dat$misinfo_treat

mod2 <- lm(data=dat,misinfo_true~Treatment + dunning_dif + Treatment*dunning_dif)

#open jpeg
jpeg(filename="fig3_alt1.jpeg",height=6,width=8,quality=100,res=300,units='in')

plot_model(mod2, type="pred", terms = c("dunning_dif","Treatment"),
           title="",
           axis.title=c("Confidence Accuracy","Skepticism [0:1]"),
           colors="bw")
dev.off()




#robustness check 1: binarized OC scale

dat$dunning_dif2 <- car::recode(dat$dunning_dif, "-1=0;0=0;1=1")

mod1 <- lm(data=dat,misinfo_true~misinfo_treat)
mod2 <- lm(data=dat,misinfo_true~misinfo_treat + dunning_dif2 + misinfo_treat*dunning_dif2)
mod3 <- lm(data=dat,misinfo_true~misinfo_treat + dunning_dif2 + misinfo_treat*dunning_dif2 + 
             know + edu)
mod4 <- lm(data=dat,misinfo_true~misinfo_treat + dunning_dif2 + misinfo_treat*dunning_dif2 + 
             know + edu + know_time_log + distract)

stargazer(mod1,mod2,mod3,mod4, type="html",out="mturk-robust1.html",
          star.cutoffs=c(0.05,0.01,0.001),
          covariate.labels=c(
            "T1: Consensus Cue",
            "T2: Large Majority Consensus Cue",
            "Confidence Accuracy [-1:1]",
            "Political Knowledge [0:5]",
            "Formal Education [1:6]",
            "Knowledge Battery Completion Time (log)",
            "Pre-Treatment Attention Check Success [0:4]",
            "T1*Confidence Accuracy",
            "T2*Confidence Accuracy",
            "Constant"
          ))


#robustness check 2: binarized OC scale


mod1 <- lm(data=dat,misinfo_true~misinfo_treat)
mod2 <- lm(data=dat,misinfo_true~misinfo_treat + dunning_dif3 + misinfo_treat*dunning_dif3)
mod3 <- lm(data=dat,misinfo_true~misinfo_treat + dunning_dif3 + misinfo_treat*dunning_dif3 + 
             know + edu)
mod4 <- lm(data=dat,misinfo_true~misinfo_treat + dunning_dif3 + misinfo_treat*dunning_dif3 + 
             know + edu + know_time_log + distract)

stargazer(mod1,mod2,mod3,mod4, type="html",out="mturk-robust2.html",
          star.cutoffs=c(0.05,0.01,0.001),
          covariate.labels=c(
            "T1: Consensus Cue",
            "T2: Large Majority Consensus Cue",
            "Confidence Accuracy [-1:1]",
            "Political Knowledge [0:5]",
            "Formal Education [1:6]",
            "Knowledge Battery Completion Time (log)",
            "Pre-Treatment Attention Check Success [0:4]",
            "T1*Confidence Accuracy",
            "T2*Confidence Accuracy",
            "Constant"
          ))

#Robustness Check 3: Treatment-Collider Interactions

mod5 <- lm(data=dat,misinfo_true~Treatment + dunning_dif + Treatment*dunning_dif + 
             know + Treatment*know + Treatment*know*dunning_dif)
mod6 <- lm(data=dat,misinfo_true~Treatment + dunning_dif + Treatment*dunning_dif + 
             distract + Treatment*distract + Treatment*distract*dunning_dif)
mod7 <- lm(data=dat,misinfo_true~Treatment + dunning_dif + Treatment*dunning_dif + 
             pidStrength + Treatment*pidStrength + Treatment*pidStrength*dunning_dif)
mod8 <- lm(data=dat,misinfo_true~Treatment + dunning_dif + Treatment*dunning_dif + 
             ideoStrength + Treatment*ideoStrength + Treatment*ideoStrength*dunning_dif)


#Fig. A1

jpeg(filename="fig3_alt1.jpeg",height=6,width=8,quality=100,res=300,units='in')

plot_model(mod5, type="pred", terms = c("dunning_dif","Treatment"),
           title="",
           axis.title=c("Confidence Accuracy","Skepticism [0:1]"),
           colors="bw")

dev.off()


#Fig. A2
jpeg(filename="fig3_alt2.jpeg",height=6,width=8,quality=100,res=300,units='in')

plot_model(mod6, type="pred", terms = c("dunning_dif","Treatment"),
           title="",
           axis.title=c("Confidence Accuracy","Skepticism [0:1]"),
           colors="bw")

dev.off()

#Fig. A3
jpeg(filename="fig3_alt3.jpeg",height=6,width=8,quality=100,res=300,units='in')

plot_model(mod7, type="pred", terms = c("dunning_dif","Treatment"),
           title="",
           axis.title=c("Confidence Accuracy","Skepticism [0:1]"),
           colors="bw")

dev.off()

#Fig. A4
jpeg(filename="fig3_alt4.jpeg",height=6,width=8,quality=100,res=300,units='in')

plot_model(mod8, type="pred", terms = c("dunning_dif","Treatment"),
           title="",
           axis.title=c("Confidence Accuracy","Skepticism [0:1]"),
           colors="bw")

dev.off()



